
new Vue({
    el: '#app',
    delimiters:['[[', ']]'],

    data: {
        banner_type: {{ banner_type }},
        banners: [],
    },

    methods: {
        requestBannerList() {
            let url = "{% url 'gma:api_get_banner_list' %}";
            let data = {
                'banner_type' : this.banner_type,
            };
            new my_ajax(url, data, '', '', (data) => {
                console.table(data);
                this.banners = data;

                this.banners.forEach(banner => {
                    banner.edit_url = `/gma/config/banner/${banner.id}/edit/`;
                });
            });
        },

        clickBanner(banner) {
            if (banner.enabled === 1) {
                this.disableBanner(banner.id);
            } else {
                this.enableBanner(banner.id);
            }
        },

        enableBanner(banner_id) {
            let data = {
                'banner_id': banner_id,
            };

            let url = "{% url 'gma:api_enable_banner' %}";
            new my_ajax(url, data, '', '', () => {
                show_toast('成功开启');
                this.requestBannerList();
            });
        },

        disableBanner(banner_id) {
            let data = {
                'banner_id': banner_id,
            };

            let url = "{% url 'gma:api_disable_banner' %}";
            new my_ajax(url, data, '', '', () => {
                show_toast('成功关闭');
                this.requestBannerList();
            });
        },
    },

    mounted() {
        this.requestBannerList();
    },
});
